package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JsonUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class StrategyDetail extends BaseDomain {

    //标题
    private String title;

    //创建时间
    private Date createTime;

    //发布时间
    private Date releaseTime;

    //序号
    private Integer sequence;

    //分类id
    private StrategyCatalog catalog;

    //封面
    private String coverUrl;

    //状态
    private Integer state;

    //文章内容
    private StrategyContent strategyContent;

    public String getJson(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("createTime",createTime);
        map.put("releaseTime",releaseTime);
        map.put("sequence",sequence);
        map.put("coverUrl",coverUrl);
        map.put("state",state);
        if (catalog != null){
            map.put("catalogId",catalog.getId());
            map.put("catalogName",catalog.getName());
            map.put("strategyId",catalog.getStrategy().getId());
        }
        if (strategyContent != null){
            map.put("content",strategyContent.getContent());
        }
        return JsonUtil.toJsonString(map);
    }

}